package com.mzy.olddate.test;

import java.util.ArrayList;

/**
 * @author Ives
 * * @date 2021/9/9
 */
public class testAdvColCode {
  public static void main(String[] args) {
    String init="020130990910010";
    System.out.println(init);

    String s = test2(init);
    System.out.println(s);
    for(int i = 0; i < 1000; i++){
      s = test2(s);
      System.out.println(s);
    }


  }
  public static String testGet(String init){

//    String substring = init.substring(0, 2);
//    String substring1 = init.substring(3, 5);
//    String substring2 = init.substring(6, 8);
//    String substring3 = init.substring(9, 11);
    String substring = init.substring(12);
    ArrayList<String> list1 = new ArrayList<>();
    for (int i = 0; i < substring.length(); i=i+3) {
      list1.add(substring.substring(i,i+2));
    }

    StringBuilder stringBuilder = new StringBuilder();
    for (String item:
         list1) {
      stringBuilder.append(item);
    }

//    StringBuilder splitJoint = stringBuilder.append(substring).append(substring1).append(substring2).append(substring3);
    String s = stringBuilder.toString();
//    System.out.println(s);
    Long aLong = Long.parseLong(s)+1;
//    System.out.println(aLong);
    String str2 = String.format("%08d", aLong);

//    System.out.println(str2);
    // 00换成01
    ArrayList<String> list = new ArrayList<>();

    for (int i = 0; i < str2.length(); i=i+2) {
      list.add(str2.substring(i,i+2));
    }
//    System.out.println(list);

//    list.add(str2.substring(0, 2));
//    list.add(str2.substring(2, 4));
//    list.add(str2.substring(4, 6));
//    list.add(str2.substring(6, 8));
//    System.out.println(list);

    ArrayList<String> newList = new ArrayList<>();
    for (int i=0;i<list.size();i++){
      if (list.get(i).equals("00")){
        newList.add("01");
      }else{
        newList.add(list.get(i));
      }
    }
    System.out.println(newList);

    StringBuilder stringBuilder1 = new StringBuilder();
    for (String item:
         newList) {
      stringBuilder1.append(item).append("0");
    }
//    StringBuilder append = stringBuilder1.append(substring4).append(substring5).append(substring6).append(substring7);
//    String str = append.toString();
//    System.out.println(str);


//    String substring4 = str2.substring(0, 2).concat("0");
//    String substring5 = str2.substring(2, 4).concat("0");
//    String substring6 = str2.substring(4, 6).concat("0");
//    String substring7 = str2.substring(6, 8).concat("0");

//    StringBuilder stringBuilder1 = new StringBuilder();
//    StringBuilder append = stringBuilder1.append(substring4).append(substring5).append(substring6).append(substring7);
//    String str = append.toString();
//    System.out.println(str);

    return stringBuilder1.toString();
  }

  public static String test2(String maximumColCode){
    String strAfter = maximumColCode.substring(12);
    ArrayList<String> list = new ArrayList<>();
    for (int i = 0; i < strAfter.length(); i=i+3) {
      list.add(strAfter.substring(i,i+2));
    }
    StringBuilder stringBuilder = new StringBuilder();
    for (String item:
            list) {
      stringBuilder.append(item);
    }
    String s = stringBuilder.toString();
    Long aLong = Long.parseLong(s)+1;

    // 补足8位
    String str2 = String.format("%08d", aLong);
    ArrayList<String> list1 = new ArrayList<>();
    for (int i = 0; i < str2.length(); i=i+2) {
      list1.add(str2.substring(i,i+2));
    }
    // 00换成01,为了错开出现1000这种情况
    ArrayList<String> newList = new ArrayList<>();
    for (int i=0;i<list1.size();i++){
      if (list1.get(i).equals("00")){
        newList.add("01");
      }else{
        newList.add(list1.get(i));
      }
    }
    // 补零还原12位
    StringBuilder stringBuilder1 = new StringBuilder();
    stringBuilder1.append(maximumColCode, 0, 12);
    for (String item:
            newList) {
      stringBuilder1.append(item).append("0");
    }
    // 截取前12位补上处理过的12位标记位并返回

    return stringBuilder1.toString();
  }
}
